package com.xiaoxu.spzx.manager.controller;

import com.xiaoxu.spzx.manager.service.SysRoleMenuService;
import com.xiaoxu.spzx.model.dto.system.AssginMenuDto;
import com.xiaoxu.spzx.model.vo.common.Result;
import com.xiaoxu.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(value = "/admin/system/sysRoleMenu")
public class SysRoleMenuController {
    @Autowired
    private SysRoleMenuService sysRoleMenuService;


    //给用户 分配 菜单  使用 sys_role_menu

    @GetMapping("/findSysRoleMenuByRoleId/{roleId}")
    public Result findSysRoleMenuByRoleId(@PathVariable("roleId")Long roleId){

        //1.查询所有的菜单 列表 ， 查询已经给用户分配的菜单

        Map<String, Object> map =  sysRoleMenuService.findSysRoleMenuByRoleId(roleId);

        return Result.build(map, ResultCodeEnum.SUCCESS);
    }


    //2.给用户分配菜单 ，删除已经存在的菜单id，添加已经✔的id放到数据库中

    @PostMapping("/doAssign")
    public Result doAssign(@RequestBody AssginMenuDto assginMenuDto){

        sysRoleMenuService.doAssign(assginMenuDto);

        return Result.build(null,ResultCodeEnum.SUCCESS);

    }

}